package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.service.ReportService;
import com.itheima.health.vo.SetmealReportParam;
import com.itheima.health.vo.GetMemberReportVO;
import com.itheima.health.vo.ReportDataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据报告控制器
 */
@RestController
@RequestMapping("/report")
@Slf4j
@Api(tags = "数据报告展示接口")
public class ReportController {

    @Autowired
    private ReportService reportService;



    @GetMapping("/getSetmealReport")
    public Result getSetmealReport(){

        Map<String,Object> data = new HashMap<>();

        List<String> setmealNames = reportService.getSetmealNames();
        data.put("setmealNames",setmealNames);


        List<Map<String,Object>> setmealCount = new ArrayList<>();
        List<SetmealReportParam> setmealReportParamList = reportService.getSetmealCount();
        for (SetmealReportParam setmealReportParam : setmealReportParamList) {
            Map<String,Object> count = new HashMap<>();
            count.put("name",setmealReportParam.getName());
            count.put("value",setmealReportParam.getValue());
            setmealCount.add(count);
        }
        data.put("setmealCount",setmealCount);
        return new Result(true,MessageConst.GET_SETMEAL_COUNT_REPORT_SUCCESS,data);

    }

    @GetMapping("/getBusinessReportData")
    public Result getBusinessReportData(){
        ReportDataVO businessReportDataVO = reportService.getBusinessReportData();
        return new Result(true,MessageConst.GET_BUSINESS_REPORT_SUCCESS,businessReportDataVO);
    }

    /**
     * 获取会员统计信息
     * @return
     */
    @GetMapping("/getMemberReport")
    public Result getMemberReport(){
        GetMemberReportVO getMemberReportVO = reportService.getMemberReport();
        return new Result(true,MessageConst.GET_MEMBER_NUMBER_REPORT_SUCCESS,getMemberReportVO);
    }

    /**
     * 导出运营数据报表
     *
     * @param response
     */
    @GetMapping("/exportBusinessReport")
    @ApiOperation("导出运营数据报表")
    public void exportBusinessData(HttpServletResponse response) {
        reportService.exportBusinessData(response);
    }


}
